package com.cos.hospital.ui.patient.compare;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cos.hospital.R;
import com.cos.hospital.model.bean.AcupointBean;

import java.util.List;

/**
 * @Description: 我的排班
 * @Author: Kosmos
 * @Date: 2018年09月16日 00:05
 * @Email: KosmoSakura@foxmail.com
 */
public class AcuAdapter extends BaseAdapter {
    private List<AcupointBean> data;//数据
    private Context context;//上下文

    public AcuAdapter(List<AcupointBean> data, Context context) {
        this.data = data;
        this.context = context;
    }


    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public AcupointBean getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder holder;
        if (convertView == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_acupoint_compare, parent, false);
            holder = new ViewHolder(view);
            view.setTag(holder);
        } else {
            view = convertView;
            holder = (ViewHolder) view.getTag();
        }
        AcupointBean bean = data.get(position);
        holder.tName.setText(bean.getFldAcupointName());
        switch (bean.getFldAcupointType()) {
            case 0:
                holder.left.setVisibility(View.VISIBLE);
                holder.right.setVisibility(View.VISIBLE);
                break;
            case 1:
                holder.left.setVisibility(View.VISIBLE);
                holder.right.setVisibility(View.GONE);
                break;
            case 2:
                holder.left.setVisibility(View.GONE);
                holder.right.setVisibility(View.VISIBLE);
                break;
            case 3:
                holder.left.setVisibility(View.GONE);
                holder.right.setVisibility(View.GONE);
                break;
        }
        return view;
    }

    private class ViewHolder {
        final TextView tName;
        final View left, right;

        ViewHolder(View root) {
            tName = root.findViewById(R.id.rec_acu_name);
            left = root.findViewById(R.id.rec_acu_i_l);
            right = root.findViewById(R.id.rec_acu_i_r);
        }
    }
}
